import Mock from 'mockjs'
import menu from '../common/js/menu'

// 拦截请求
Mock.mock('/login', 'post', (data) => {
    const { username } = JSON.parse(data.body);
    if (Object.keys(menu).includes(username)) {
        return {
            code: 10000,
            data: {
                token: `${username}-${Mock.Random.string(6)}`,
                menu: menu[username]
            },
            message: '登录成功'
        }
    } else {
        return {
            code: 10001,
            data: {},
            message: '账号不存在'
        }
    }
})
